package cn.edu.dyxy.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 编码过滤器
 *
 * @author waqwb
 */
@WebFilter("/*")
public class EncodingFilter implements Filter {

    /**
     * 销毁方法
     */
    @Override
    public void destroy() {

    }

    /**
     * 过滤方法
     */
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        // 执行请求之前处理字符集，设置为UTF-8
        request.setCharacterEncoding("UTF-8");
        // 处理返回数据的编码集，设置为UTF-8
        response.setCharacterEncoding("UTF-8");
        // 执行请求
        chain.doFilter(request, response);
    }

    /**
     * 初始化方法
     */
    @Override
    public void init(FilterConfig fConfig) throws ServletException {

    }

}
